HTML5 Geolocation

This book is intended for developers interested in using the W3C Geolocation API in their web applications.


Antony T. Holdener


103 Pages

7650 Reads

58 Downloads

English

PDF Format

1.72 MB

HTML Learning

Download PDF format


  • Antony T. Holdener   
  • 103 Pages   
  • 26 Feb 2015
  • Page - 1

    read more..

  • Page - 2

    HTML5 Geolocation by Anthony T. Holdener III Copyright © 2011 Anthony T. Holdener, III. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles read more..

  • Page - 3

    Table of Contents Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi 1. Finding Our Way . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . read more..

  • Page - 4

    Accuracy 29 3. Geolocation API in Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 W3C Geolocation API 31 Current API Support 32 Other Browser Solutions 32 The W3C Geolocation API Does More 35 The Geolocation Object 35 Get the User’s Position 36 PositionOptions 37 Cached read more..

  • Page - 5

    Geosocial 82 Continued Growth 82 Automatic Check-in 83 Two Way Street of Data 84 Geotagging 85 Digital Media and Geotagging 85 Privacy and Geotagging 85 Geo-applications 86 Safety/Tracking 86 Taxi Services 86 Search 87 M-Commerce 87 Other Applications 87 HTML5 and Geolocation 87 Web Applications Supplementing LBS 88 Web-Based LBS 94 Table of Contents | ix read more..

  • Page - 6

    Preface This book explores the W3C Geolocation API, a specification that provides scripted access to geographical location information associated with a hosted device.* This API defines objects that can be used in JavaScript to ascertain the position of the device on which the code is executed. The term geolocation may refer to the act of identifying a person’s po- sition, or read more..

  • Page - 7

    The simple fact is that we associate HTML5 and Geolocation. So to avoid any confusion that might have arisen had I not used HTML5, and since neither myself nor my editor could really come up with a snazzier title for this book, HTML5 Geolocation stuck. Audience for This Book This book is intended for developers interested in using the W3C Geolocation API in their web read more..

  • Page - 8

    This icon indicates a warning or caution. Using Code Examples This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from read more..

  • Page - 9

    Sebastopol, CA 95472 800-998-9938 (in the United States or Canada) 707-829-0515 (international or local) 707-829-0104 (fax) We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at: http://www.oreilly.com/catalog/9781449304720 To comment or ask technical questions about this book, send email to: bookquestions@oreilly.com For more read more..

  • Page - 10

    CHAPTER 1 Finding Our Way As long as people have been traveling from one place to another on Earth, they have used a variety of methods, with varying degrees of accuracy, to calculate approximately where they are located at any given time. As our technologies have improved, so has our ability to detect our position accurately. The term geolocation is best described as the read more..

  • Page - 11

    Greeks, Phoenicians, Norse, Persians, and Chinese all used the stars to assist in navi- gating the seas, developing tools, like those discussed further later, which allowed them to venture out past the sight of land. The ability to venture farther and farther from their homes led to the discovery of new lands and the spread of their respective civilizations. Technology with read more..

  • Page - 12

    had begun using the quadrant as a supplement for the astrolabe in many cases, also used to measure angles, but by measuring the projection of the shadow cast by a body like the sun. The quadrant began as a simple pole and attached arc, but evolved over time to a more complicated device with multiple poles and arcs, such as the Davis quadrant. All of the devices to read more..

  • Page - 13

    Location in the 1900s By the beginning of the 20th century, radios were used on ships to check the accuracy of the ship’s chronometer and for determining direction (while also being used for communication, of course). This is accomplished by calculating a path based upon the direction that the signal was received from some source transmission, known as Di- rection finding read more..

  • Page - 14

    the Doppler effect, the signal from Sputnik grew higher in frequency as the satellite got nearer to their observation posts and lower as it moved away. Using Doppler distor- tion, scientists realized they could tell exactly where the satellite was in its orbit at any given time. The Doppler Effect was first discovered by Austrian physicist Christian Doppler. It describes the read more..

  • Page - 15

    Geolocation Now Since 1978, 59 GPS satellites have successfully been placed in orbit around the Earth, although as of 2010, only 30 of those satellites were still considered healthy. The United States plans to launch more GPS satellites into orbit over the next several years and has also entered into a cooperative agreement with the European Union for use of their Galileo read more..

  • Page - 16

    Geocoding is the method of identifying the geographic coordinates as- sociated with textual location information like street address or postal code. Reverse geocoding is essentially the opposite process—using as- sociated textual location information based on a geographic coordinate. Of course, the position does not necessarily have to come from a GPS system. The information used and read more..

  • Page - 17

    The receiver determines the time it takes to receive each message and then calculates the distance to each satellite based on this information. The distance of each satellite from the receiver, their current orbit, and the trilateration calculations inform the re- ceiver of its own current position. While in radio triangulation three transmitters are enough to determine a reasonable read more..

  • Page - 18

    The ephemeris provides orbital information and clock corrections for the specific sat- ellite. The almanac also provides data containing orbital information and clock cor- rections, but for the entire satellite array. The almanac data is not very precise and may be valid for up to four months while ephemeris data is very precise and valid for, at most, 30 minutes. The following read more..

  • Page - 19

    that there are hundreds of these regional institutes that would need to be queried in order to gain the data—an impractical prospect. Though the geolocation found from a device’s IP address has gotten much more accurate in recent years, it can still be misleading or off by miles. The location returned could be the location of the ISP itself, a proxy server, firewall, or read more..

  • Page - 20

    a given band, something that GSM cannot do. CDMA networks, like GSM, are also migrating to LTE technologies to support the growing demand for 4G networks. Regardless of what type of technology the mobile device is using, the basic principle of having a unique identifier on the network is what really matters. Using triangulation, the Cell ID’s latitude and longitude can be read more..

  • Page - 21

    A location-based service (LBS) is usually a service running on a mobile device that pro- vides facts or recreational information. It employs geolocation to make the facts or entertainment more personal to the user of the application. An example of a typical location-based service is one that identifies the location of a device and then discovers the location of restaurants in read more..

  • Page - 22

    specialized searching based on location, real-time tracking, and emergency services applications. Mobile Applications Mobile geolocation applications have been growing in popularity since 2004, with the development of one of the first modern social media applications: Yelp. There were other applications that came before Yelp, but this application seemed to have a broader appeal—the coming read more..

  • Page - 23

    privacy) on Android phones, the basic ability to share your location with others and see where your friends are is available on pretty much every platform around today. Latitude is Google’s solution for a social media check-in application, but this just scratches the surface of social media applications available. Not too long after Yelp was launched, Loopt was created by two read more..

  • Page - 24

    Location-sharing Applications Glympse was founded in 2008 by three ex-Microsoft employees—Bryan Trussel, Jeremy Mercer, and Steve Miller—with a different approach for sharing location in- formation with others. Glympse, like Google Latitude, restricts who can see a user’s location to only those that the user chooses. The difference from all other geolocation applications, however, is read more..

  • Page - 25

    The location-sharing application market will continue to grow, as the idea of permitting others to view where you are without having to interact with the application becomes a more comfortable idea. Privacy concerns will be the main hurdle for these types of applications. The market may see more inventive geolocation solutions to these loca- tion-based services if consumers can be read more..

  • Page - 26

    Figure 1-6. Yelp Monocle in action on Android As we move farther from inception of these initial augmented reality applications, we should expect to see many more offerings in this particular market. Augmented reality is a cutting-edge technology that, combined with geolocation, has the potential to offer some truly spectacular applications very soon. Geolocation Today | 17 read more..

  • Page - 27

    CHAPTER 2 Geolocation: Latitude, Longitude, and More In Chapter 1, we covered the basics of geolocation, including what geolocation means, how geolocation information is gathered from different sources depending upon the device, and some common applications that implement geolocation today. Several key terms have also been mentioned, like latitude, longitude, and altitude; yet no definition read more..

  • Page - 28

    Latitude and Longitude To understand how latitude and longitude works, picture a globe with lines running both horizontally and vertically at (roughly) equal spacing between them, as shown in Figure 2-1. I mention roughly because, as we will see in “The Earth’s Shape” on page 23, the Earth is not a perfect sphere, and there will be small variations in the spacing of the read more..

  • Page - 29

    and western hemispheres. Longitude is expressed by λ, or the lower-case Greek letter lambda. Prior to 1884, any seafaring nation could set its own “zero” longitude when it issued navigational charts. This happened quite often over the centuries. In fact, this practice dates back to that first Alexandrian scholar who selected the Egyptian city of Alexandria as the first “zero” read more..

  • Page - 30

    3. Add this fraction to the whole number of degrees. 4. If the coordinate is a South latitude or West longitude, negate the result. We will follow these steps to convert the longitude part of the Arch’s coordinate, 90°11'7"W, to see these steps in action: 1. Calculate the total number of seconds: 11'7" = ((11 * 60) + 7) = 667. 2. Take this total and divide it read more..

  • Page - 31

    Geodetic Systems and Datums If everything were simple, the geographic coordinate system would be enough to de- scribe where points fall on the Earth. Because of the Earth’s irregular shape, however, things are not quite so simple and a system was needed to translate positions indicated on maps to their real positions on the Earth. This system is called a geodetic system. The read more..

  • Page - 32

    used to satisfy simplifying the Earth into simpler two- and three-dimensional models everyday users can consume. Common Datum As Mathematicians modified and recalculated their ideas of the Earth’s shape and size, the datums that they used had to be modified as well. There have been many different datums over time, and these datums have evolved from ones that described the Earth read more..

  • Page - 33

    • Japanese Datum (TOKYO) • Pulkovo Datum (S-42) The differences in the coordinates between any two datums is called the datum shift, and is an important consideration when looking at a map. The shift between datum depends on many factors, including the elevations of the datum in question. For ex- ample, while the difference between WGS 84 and NAD 83 is very small (less read more..

  • Page - 34

    map of the entire globe, it becomes more challenging. Using a datum as a reference, a map is projected to display certain aspects of the Earth—scale, distance, area, shape, etc. No map can, unfortunately, protect every aspect and there will have to be com- promises on some aspects in order to preserve others. On the Web, all major vendors in map data (Esri, Google, read more..

  • Page - 35

    Geodetic Height Without an elevation, a point cannot be pinpointed exactly on a topographic feature. This height, when discussed in reference to a geolocation, is generally understood to be above sea level, though it does not have to be defined this way. As our technologies advance and more diverse environments open up to us, it is quite possible that we will find uses for read more..

  • Page - 36

    Course An object’s course is the proposed direction that it will take to get from one point to another. It can be defined as a planned route between two points, or it can be defined as the necessary path an object must take to get from one point to the next. A course is constructed out of straight lines between points, with each segment of the course being read more..

  • Page - 37

    Though the SI unit of speed is meters per second, more familiar units of measure (ones used in cars every day) are units like miles per hours and kilometers per hour. Accuracy In a perfect world, the location you are given when requesting geolocation information would be exactly right—meaning where it says you are is where you actually are. Well, the world is not perfect read more..

  • Page - 38

    Of course, hardware glitches, radio interference, weather, and so on can degrade signals and decrease the accuracy of any geolocation request at any time. That is why it is important to gather accuracy information whenever a geolocation request is made, so that the user can be made aware of potential errors in their location in an application. The accuracy of geolocation read more..

  • Page - 39

    CHAPTER 3 Geolocation API in Code At this point, I am sure there are a lot of you reading this that are thinking to yourself, “Thank you, Mr. Author, for all of that lovely background information on what geo- location is, but can we see how to do this in code, already?” If that is you, then you are in luck, because this chapter is all about coding with the read more..

  • Page - 40

    The latest version of the W3C Geolocation API Specification is W3C Candidate Recommendation 07 September 2010. Current API Support Currently, the W3C Geolocation API is supported by most modern browsers on both the desktop and on mobile phones. Table 3-1 shows the current browser support for the API. The biggest issue developers will face is that older browsers have obviously not read more..

  • Page - 41

    Gears Gears, formally known as Google Gears, is (as the name obviously suggests) a code library written by the good folks over at Google, Inc. Gears is designed to be an open source project that enables more powerful web applications by adding new features to the web browser. The component of Gears that most interests us is the Geolocation module, which acts very much like read more..

  • Page - 42

    compliant browsers or support, which would eliminate the mess that developers cur- rently face. Which brings us to... geo-location-javascript geo-location-javascript is an attempt to build a JavaScript framework that will wrap all of the underlying platform implementations into a single API that works similarly to the W3C Geolocation API Specification. The following platforms are currently read more..

  • Page - 43

    the user. The geo-location-javascript API, like all other Geolocation APIs, including the W3C Geolocation API, requires the user to opt in and allow the location to be collected before proceeding. Learn more about that in “Privacy” on page 45 . There are two callback functions in the call to geo_position_js.getCurrentPosi tion(): show_position and error_handler. If anything were to go read more..

  • Page - 44

    if (window.navigator.geolocation) { // do some geolocation stuff } else { // the browser does not natively support geolocation } In the preceding code, the existence of an implementation of the geolocation property is tested, and if it exists, the code will do geolocation processing, otherwise something else will need to be tried. The Geolocation object contains three read more..

  • Page - 45

    if (window.navigator.geolocation) { navigator.geolocation.getCurrentPosition(successCallback, errorCallback, options); } else { alert('Your browser does not natively support geolocation.'); } function successCallback(position) { // Do something with a location here } function errorCallback(error) { // There was a problem getting the location } PositionOptions The PositionOptions read more..

  • Page - 46

    This code calls getCurrentPosition(), requesting high accuracy, and a cached position no older than 60 seconds, with a timeout period of 45 seconds before returning an error. Cached Positions A cached position is a position that was gathered by the application sometime in the past that may be used again instead of requiring a new position to be fetched. When it is not read more..

  • Page - 47

    var watcher = navigator.geolocation.watchPosition(successCallback, errorCallback, options); The first parameter, successCallback, will be called when a successful position has been gathered by the API. The second parameter, errorCallback, is optional and will be called when there is an error in gathering a position. The final parameter, options, is a read more..

  • Page - 48

    Clearing a Watch Operation Like the JavaScript clearTimeout() and clearInterval() methods, the W3C Geoloca- tion API provides a method for clearing a watch operation by passing the desired watchId to the clearWatch() method. The syntax is: navigator.geolocation.clearWatch(watcher); The following code demonstrates creating a new watch operation, and then removing that watch upon the read more..

  • Page - 49

    Coordinates Object The main geographic information gathered by the API is held in a Coordinates object which is a property of the Position object (see “Position Object” on page 40). This information is in the World Geodetic System reference system WGS 84. More infor- mation on this reference system can be found in “WGS 84” on page 25. Currently, no other reference read more..

  • Page - 50

    function successCallback(position) { var output = ''; output += "Your position has been located.\n\n"; output += 'Latitude: ' + position.coords.latitude + "°\n"; output += 'Longitude: ' + position.coords.longitude + "°\n"; output += 'Accuracy: ' + read more..

  • Page - 51

    ((this.sign > 0) ? 'E' : 'W'); this.toString = function(dir) { if (isNaN(dir)) return (this.deg * this.sign) + "\u00b0 " + this.min + "' " + this.sec + '" '; else return this.deg + "\u00b0 " + this.min + "' " + this.sec + '" ' + this.dir; }; } read more..

  • Page - 52

    Table 3-6. PositionError object properties Property Description code The code is a numeric value alerting the developer to what the error is. The code will be one of the following values: PERMISSION_DENIED (1) The location call failed because the application does not have the necessary permissions to use the Geolocation API. POSITION_UNAVAILALE (2) The location call failed because the read more..

  • Page - 53

    output += 'Altitude Accuracy: ' + position.coords.altitudeAccuracy + " meters\n"; if (position.coords.heading) output += 'Heading: ' + position.coords.Heading + "°\n"; if (position.coords.speed) output += 'Speed: ' + position.coords.Speed + read more..

  • Page - 54

    allow access for the site with a checkbox indicating this site-level access, which can be undone at any time within the settings of the browser itself. From a development standpoint, should the user decide not to grant your application access to his location information, you should make sure that your application can handle this gracefully. Unless the user has granted the read more..

  • Page - 55

    CHAPTER 4 Geolocation and Mapping APIs Chapter 3 introduced us to using the W3C Geolocation API to collect location infor- mation from the user’s browser with JavaScript code. Although that is the whole point of this book, it is not extremely useful to collect geolocation information unless you, the developer, are going to do something with it. One effective application for read more..

  • Page - 56

    being built. It is a very popular API for building web applications, currently being used in over 150,000 websites.† The Google Maps API, Briefly For the purposes of this book, I have included all of the code for the Google Maps application into a single HTML file to make it easier to read. If I were to create an actual application, I would break the Cascading Style read more..

  • Page - 57

    style: google.maps.ZoomControlStyle.LARGE, position: google.maps.ControlPosition.LEFT_CENTER }, scaleControl: true, scaleControlOptions: { position: google.maps.ControlPosition.BOTTOM_LEFT }, streetViewControl: true, read more..

  • Page - 58

    The code in Example 4-1 produces a map like that shown in Figure 4-1. I will step through this code in more detail in a moment, but there are several things that should be noted right away: • The application is written in HTML5. • The Google Maps JavaScript API is included in the application by calling it from Google’s site. • There are a couple of utility read more..

  • Page - 59

    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> This makes the latest version of the API available for the application. The parameter sensor is set to false to indicate that the map is not using a sensor to determine the user’s location. When geolocation is added to Example 4-1, the value of the sensor pa- read more..

  • Page - 60

    mapType The Google Maps JavaScript API makes the following map types available: ROAD MAP, SATELLITE, HYBRID, and TERRAIN. mapTypeControl, panControl, zoomControl, scaleControl, streetViewControl These controls are toggled on or off with values of true and false. In addition, each has specific configuration options along with a position property. For more information on options available for read more..

  • Page - 61

    function InitMap() { /* Set all of the options for the map */ var options = { zoom: 4, center: new google.maps.LatLng(38.6201, -90.2003), mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeControl: true, mapTypeControlOptions: { read more..

  • Page - 62

    var point = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); var marker = new google.maps.Marker({ position: point }); marker.setMap(map); map.setCenter(point); map.setZoom(15); } /* Report any read more..

  • Page - 63

    Utils.removeEvent = (function() { return function removeEvent(event) { if (event.preventDefault) { event.preventDefault(); event.stopProgagation(); } else { event.returnValue = false; event.cancelBubble = true; read more..

  • Page - 64

    solution using the geo-location-javascript library. Again, changes and additions to the code are highlighted in bold for easier identification. Example 4-3. Adding geolocation for other browsers to a Google Map <!DOCTYPE html> <html lang="en"> <head> <title>Adding Geolocation for Other Browsers to a Google Map</title> <meta name="viewport" read more..

  • Page - 65

    /* Create a new Map for the application */ map = new google.maps.Map(document.getElementById('map'), options); /* Add Geolocation */ getLocation(); } /* * The browser will now use whatever geolocation API is available to * it; hopefully read more..

  • Page - 66

    } else { eventObj['on' + event] = function() { eventHandler() }; } }; }()); Utils.removeEvent = (function() { return function removeEvent(event) { if (event.preventDefault) { event.preventDefault(); read more..

  • Page - 67

    use. Many sites use this API for their GIS needs, especially when their desktop and server GIS needs are met using Esri enterprise software. At the time of this writing, the current version of the API is 2.2. The ArcGIS JavaScript API, Briefly Again, for this book, I have included all of the code for the ArcGIS JavaScript Map application into a single HTML file to make read more..

  • Page - 68

    ymin: 26.3156, xmax: -72.3568, ymax: 55.0558, /* * Web Mercator (102113), or WGS 84 (4326) - these are the * only two that support continuous pan across the date line */ spatialReference: { wkid: 4326 } }; read more..

  • Page - 69

    Figure 4-2. A simple Esri ArcGIS Map in Chrome The Esri ArcGIS JavaScript API and Dojo Toolkit are included in the application with the following line: <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.2"> </script> The version of the API you wish to use is specified in the querystring of the API call, in this case the read more..

  • Page - 70

    API, the map would not scroll across the date line like other web-mapping applications do. For more information on options available for the Map object, or API details in general, visit the ArcGIS API for JavaScript Resource page. Adding Geolocation to Esri Maps You probably noticed the similarities between the map applications in Example 4-1 and Example 4-4 or, more read more..

  • Page - 71

    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.2"> </script> <script type="text/javascript"> dojo.require('esri.map'); var map; var initialExtent = { xmin: -119.3324, ymin: 26.3156, read more..

  • Page - 72

    /* Plot the location on the map and zoom to it */ function plotLocation(position) { attempts = 0; var pointsLayer = new esri.layers.GraphicsLayer(); map.addLayer(pointsLayer); var point = new esri.geometry.Point(position.coords.longitude, position.coords.latitude, new read more..

  • Page - 73

    <body class="claro"> <div id="map"></div> </body> </html> In this example, the call to the getLocation() function is inside an anonymous function that will be called on an onLoad event from the Map. Next, we define our two callback functions: plotLocation() and reportProblem(). The reportProblem() function is exactly like its read more..

  • Page - 74

    height: 100%; width: 100%; } </style> <script type="text/javascript"> var djConfig = { parseOnLoad: true }; </script> <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.2"> </script> read more..

  • Page - 75

    * then report the problem. */ function getLocation() { /* Check if the browser supports any geolocation API */ if (geo_position_js.init()) { browserSupport = true; geo_position_js.getCurrentPosition(plotLocation, reportProblem); read more..

  • Page - 76

    Instead of checking for navigator.geolocation, the geo-location-javascript init() func- tion is called, which returns whether or not the browser supports any geolocation API. A simpler call to getCurrentPosition() is made, without the timeout set, but otherwise the getLocation() function is very similar to this same function in Example 4-5. Nothing changed between the two Esri read more..

  • Page - 77

    CHAPTER 5 Saving Geographic Information Many applications do more than display a geolocation on a map once it has been ac- quired. In many cases, the location is saved for later use—possibly displaying a history of where a user has been, or showing where many users are at any given time. In these cases, the browser application will need to collect the geolocation of the read more..

  • Page - 78

    solutions to a problem is important knowledge that I hope you take advantage of in your own projects. I will focus on only three of the ways data can be saved—KML, Shapefiles, and rela- tional databases—because they are all popular ways of saving geographic information. If none of these proves to be a good method for your needs, hopefully it will at least aid you in read more..

  • Page - 79

    Placemark is similar to the Floating Point Placemark in that it is at a specific height above the ground, but it is tethered to the ground by a customizable tail. All three of these types are controlled by the data inside the <Point> element of the <Placemark>. The following illustrates the syntax of a Point Placemark, showing the child elements that would be read more..

  • Page - 80

    <coordinates>-90.185278,38.624722,212</coordinates> </Point> </Placemark> <Placemark id="pt_000001"> <name>Point 000001</name> <description>This is the second point collected.</description> <Timestamp><when>2011-04-07T00:15:37+06:00</when></Timestamp> read more..

  • Page - 81

    Shapefiles A shapefile is a data format designed for holding geographical vector data like points and polygons along with associated attribute data. It was developed by Esri and is maintained by it. It was specifically designed as a spatial data format for use with Esri’s ArcGIS Desktop product, though it works with other software as well. Some other software that can utilize read more..

  • Page - 82

    Python Shapefile Library The Python Shapefile Library (PSL) was written by Joel Lawhead. It provides read and write capabilities for shapefiles using the Python scripting language. It is designed to be as extensible as it can be when creating a shapefile while still having some validation to ensure a proper file is produced. Take a look at Example 5-2. Example 5-2. Creating a read more..

  • Page - 83

    to true. This verifies that when a point or a record is added with the script, the opposite is also added (every point has a record and every record has a point). Next, the points are added with the point() method. The point() method takes a latitude, longitude, and optional altitude and measure. In Example 5-2, the latitude, longitude, and altitude of each point is read more..

  • Page - 84

    Spatial databases are built so that the spatial data and attributes coexist in the same database. MySQL, DB2, Oracle, and Microsoft SQL Server (starting with 2008) all can store spatial information natively in their tables. In some cases, however, additional software is placed on top of the RDBMS in order to facilitate geographic functionality (especially querying) within the read more..

  • Page - 85

    ST_Intersects() function. The results of this query is the geometry associated with each geolocation found within a city park with an area greater than 10,000 feet. MySQL MySQL is the world’s most popular open source database, in use by some of the most heavily visited websites like Google, Wikipedia, YouTube, and Facebook. Instead of requiring additional software on top of read more..

  • Page - 86

    speed DECIMAL(7, 4) NULL, timestamp DATETIME NOT NULL, name VARCHAR(20) NOT NULL, description VARCHAR(80) NULL ); This example creates a new database called geolocations, and then creates a table called positions that holds all of the attribute data that can be collected read more..

  • Page - 87

    CHAPTER 6 What You Can Do with Geolocation There is no doubt that geolocation will continue to grow for years to come—just look at the ever-increasing trends among the popular location-based services for mobile phones to see why. While Foursquare, Gowalla, Twitter, Glympse, and all the rest continue impressive growth (and will continue to do so for quite some time), the W3C read more..

  • Page - 88

    Finally, techniques for IP address tracking are improving as research and interest grows in geolocation. A computer scientist at the University of Electronic Science and Tech- nology of China in Chengdu, Yong Wong, along with colleagues at Northwestern University in Evanston, Illinois, developed a method to identify a device using only an IP address to within 100 meters (690 meters read more..

  • Page - 89

    Geomarketing in the future will rely more on the customer’s current location, with applications that track the user’s movements playing a large part in allowing companies to promote specials that pertain to certain locations. A scenario like the following will be possible: A person turns his vehicle onto a busy road lined with stores. A text mes- sage, email, or some other read more..

  • Page - 90

    Specialization One of the goals of geomarketing, from a business’s point of view, is to be able to deliver marketing and advertisements that are specific for a location to the customer. Web- based advertisements are using geolocation to deliver content that is relevant to a city level. The location is most likely found based upon IP address, so it makes sense to only read more..

  • Page - 91

    media market continues to grow, it will face challenges that it must meet and resolve before it can go truly mainstream. Once it does, it will go from a multibillion dollar industry to a multi-?? dollar industry. The security that is implemented by the application is also very important for the users of the application. When the user passes information to the application for read more..

  • Page - 92

    simply check the user in at the location without notifying him at all. Shopkick already takes advantage of the automatic check-in, and more applications will follow with time. Two Way Street of Data The data for a social media application flows from both the application and the user. The user provides information to the application, such as his current location and thoughts read more..

  • Page - 93

    Geotagging Geotagging is defined as adding geospatial metadata to digital media such as photo- graphs, videos, text messages, tweets, and web pages. The geospatial information usu- ally captured in the metadata is latitude and longitude, altitude, accuracy, and heading. Other information may also be gathered based on the type of media in question. As you can see, the geospatial read more..

  • Page - 94

    At some point, though, users will have to ask themselves whether they trust the pro- viders to properly handle and secure their content. If the answer to that question is no, then these users should opt-out of geotagging their tweets and videos, and remove geographic information from photos that are uploaded to public sites. Media sites pro- vide services, and it is up to read more..

  • Page - 95

    Search Searching can become more personalized if it is supplemented with geolocation. This can work with desktop computers as well, as it is not specific to smartphones. When a user searches for something, when relevant, the search engine could take into account the user’s geolocation and return search results factoring in location. This could give users the result they are read more..

  • Page - 96

    Web Applications Supplementing LBS A good use of HTML5 is in supplementing mobile geolocation applications. Take Twitter, for example. It is possible to view a feed of all recent tweets within a certain buffer range of a specific coordinate. You could pick a coordinate by clicking on a map, and then displaying all tweets within 500 meters of that locations. Better yet, you read more..

  • Page - 97

    html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map { height: 100% } .tweet_info { border: 1px solid #000; padding: 15px; width: 300px } .tweet_info img { float: right; height: 48px; margin: 0 0 10px 10px; width: 48px } .tweet_info h3 { read more..

  • Page - 98

    }, reportProblem, { timeout: 45000 }); } else reportProblem(); } /* Create the URL that will call the Search API REST end point */ function createTweetSearchURL() { var temp = map.getCenter(); return 'http://search.twitter.com/search.json' + read more..

  • Page - 99

    plotTweet(tweet); } } } /* Create the content for the information pop up window */ function createInfoContent(tweet) { var retval = ''; retval += '<div class="tweet_info">'; retval += '<img alt="' + read more..

  • Page - 100

    'not get the most out of the application now.'); break; case e.POSITION_UNAVAILABLE: alert('There was a problem getting your position.'); break; case e.TIMEOUT: /* read more..

  • Page - 101

    A JSON object is returned by the Twitter Search API. The JSON object is structured like the following: { "results": [ { "from_user_id_str" : "111111111", "location": "St. Louis, MO", "profile_image_url": "http://a1.twimg.com/profile_images/111111111/my_profile_pic.gif", read more..

  • Page - 102

    "next_page": "?page=2&max_id=99999999999999909&rpp=100&geocode=38.111111%2C \ -90.555555%2C50.0km&q=", "results_per_page": 100, "page": 1, "completed_in": 0.162742, "warning": "adjusted since_id to 99999999999999902 (), requested since_id \ was older than allowed -- since_id removed for pagination.", read more..

  • Page - 103

    existing applications as a web application version of themselves, but the development of new geolocation applications could most certainly be built for the browser. Building for the web browser serves several purposes. Overall development costs should be lower since it can be programmed with only one code base (HTML, CSS, JavaScript, and a server-side scripting language) instead of a read more..

Write Your Review