google maps - Average Lng/Lat NaN Issues -
I am an amateur programmer and I have to work on a project using the Google Maps API. Short story short, I am trying to create a variable with the average latitude of the number of digits and the latitude. I am at this point that I have an array of LNG / LIT coordinates, but I am struggling to convert them into a format which I can use as an input for a Google Maps LatLng method.
I have now referred to such questions for a month, and many other websites, but I am not able to understand or implement a solution. I think I can not find simple stuff, but I am beaten against it for a month and I am not getting anywhere. Any advice or assistance with this will be appreciated.
// Streetser = document on Google Maps API scripts.getElementsByName ("street"); Var cityarray = document.getElementsByName ("city"); Var Geododer; Var map; Various results; Var maparre = new array (); Var avgLat; Var avgLng; Start the function () {geocoder = new google.maps.Geocoder (); Var latlng = new google.maps.LatLng (-34.397, 150.644); Var mapOptions = {Zoom: 8, // focuses on Carrollton, Texas - Latitude to change the initial map area center, change long value: new google.maps.LatLng (32.999173, -96.897413)} // change ID div reference / Container in which the map of Google Maps is = new google.maps.Map (document.getElementById ('map'), map options); } Function codeAddress () {// for all regions (var cName = 0; cName & lt; namearray.length; cName ++) {var address = streetarray [cname] to find long, latitude values for street and Lapse through city prices. Value + cityairrease [cname]. value; // Start Geocode Copy & amp; Paste text from API reference geocoder.geocode ({'address': addresses}, function (result, status) {if (status == google.maps.GeocoderStatus.OK) {var results = result [0] .geometry.location Map.setCenter (results); var markers = New google.maps.Marker (Map: map, position: result,}) // Push LNG maps / Map locations at the mapRepeut (result); // MapArray Wave through loop To add the LG value, and then divide the average (for the number of places) for mapArray in var {var avgLat = 0; var avgLng = 0; var j = 0; var avgLat = (avgLat) + mapare [i] [1]); Var avgLng = (avgLng + mapArray [i] [2]); Console.log (MAPARA, AGLAT, AGLNG); J ++;} avgLat = avgLat / j; AvgLng = avgLng / j; Var MarkerCrinal = new google.maps.Circle ({center: result, radius: 15000, stroke color: "# 0000ff", stroke opacity: 0.8, strokewhite: 2, fill collar: "# 0000ff", fillipity: 0.4} ) Marker Carroll (Map);} Other {warning ('Geocode was not successful for the following reason:' position);}}); }}
2 problems:
-
Result [0] .geometry.location is not an array, it is an object (a google.maps.LatLng ). Use lat () and lng () to achieve latitude and longitude -
var avgLat = 0;
var avgLng = 0;
var j = 0; . You should take it out of the loop, otherwise the variables will be cleared on each loop.
Comments
Post a Comment