I am using google maps v3, Currently it is working fine, if i pass the latitude and longitude in 'position'. But, I need to pass address instead of latitude and longitude.
var ll = new google.maps.LatLng(dat_values[i].lat, dat_values[i].lng);
var marker = new google.maps.Marker({
position: ll,
icon: myImage,
shadow: myShadow,
});
Kindly anyone suggest.
thanks,
Here's another similar approach:
$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address=573/1,+Jangli+Maharaj+Road,+Deccan+Gymkhana,+Pune,+Maharashtra,+India&sensor=false');
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;
From:
http://amiworks.co.in/talk/how-to-get-latitudelongitude-from-an-address-or-geocoding-using-php/
You've have to use the Geocoder service to convert the address into a LatLng.
Related
i am working on google map flutter and i added multiple markers on map. so i want to draw route between user location and the marker clicked
for (int i = 0; i < lat.length; i++) {
_markerIdCounter++;
markerId = MarkerId('marker_id_$_markerIdCounter');
double la = lat[i];
double lo = long[i];
destPosition = LatLng(la, lo);
address = await geolocator.placemarkFromCoordinates(
destPosition.latitude, destPosition.longitude);
Placemark place = address[0];
_markers.add(Marker(
markerId: markerId,
position: destPosition,
icon: destinationIcon,
infoWindow: InfoWindow(title: place.name.toString()),
onTap: () {
var options;
_onMarkerTapped(markerId);
LatLng des = destPosition;
LatLng cu =
LatLng(currentLocation.latitude, currentLocation.longitude);
getDistanceTime(cu, destPosition);
setPolylines(destPosition);
}));
One option is to use the google maps directions API that will return you a ROUTE object that contains everything you may need to draw the path(polyline) based on the props you've sent to it( for example str address A to str address B or lat long A to lat long B etc...). Click here for full API doc ref
You can use flutter_polyline_points package. It's a plugin the uses Google Maps Directions API to show route/polylines on maps. Make sure you have a valid API key and Directions API enabled on your Google cloud console to use it.
You can create a method that accepts latlng coordinates of your marker and then call that method every time you click the marker. Kindly check out the examples in the package doc for more details.
I'm using google maps API to determine a building(Place) which is a Google Point of interest. I'm trying to get the place reference for future use. but due to API limitation or whatever limitation. I can't get the exact place. As an example below latitude longitude belongs to "The university of Sydney". Using this code I could derive University of Sydney but as second result and also I tried many lat long but sometime appropriate result comes in the end or first. These places are prominent to Google Places Search system. The radius of this request looks lame to me. Is there any way to retrieve the exact place ?
var pyrmont = new google.maps.LatLng(-33.88858402464521, 151.18735671043396);
map = new google.maps.Map(document.getElementById('map-canvas'), {
center: pyrmont,
zoom: 15
});
var request = {
location: pyrmont,
radius: 1,
};
infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
}
Advanced Thanks
I have data of a location's latitude and longitude. I want to display it into a map in my application. I planned to use Google Maps to display this location to user.
To do this, would I need the Google Maps API? or the Google Maps Coordinate?
I've looked into their website, but all those varieties just makes me confused.
I only need it to display the data (latitude and longitude) into visual (map) to make my application more user-friendly.
I have never used Google Maps API before, so for those that have experience in it, please guide me.
Google Maps API : http://www.google.com/enterprise/mapsearth/products/mapsapi.html#
Google Maps Coordinate: http://www.google.com/enterprise/mapsearth/products/coordinate.html?rd=1#
On a side note, I might sell the application (using subscription), so I would need the Google Maps API license. Anyone know how much it is and how is the procedure? (e.g., monthly or yearly basis, per user or per use, etc.)
EDIT
Or is there any other API for the mapping? something like Google Maps API.
We have to give latitude and longitude .
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
window.onload = function () {
var mapOptions = {
//give latitude and long
center: new google.maps.LatLng("18.9750", "72.8258"),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var infoWindow = new google.maps.InfoWindow();
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
//give latitude and long
var myLatlng = new google.maps.LatLng("18.9750", "72.8258");
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: "Mumbai"
});
}
</script>
<div id="dvMap" style="width: 500px; height: 500px">
I have an old gmaps application using V2 and I am trying to update it to v3.
I have a really simple problem, but I can't find a solution yet.
How can I strip the latitude and the longitude from the "event.latLng"?
It is returning a point(), but I need only the lat alone and the long for itself.
I cant get this to work.
According to the API for MouseEvents, event.latLng contains a LatLng, not a Point. If this is the case then you can use the lat() and lng() methods to get the values separately. If event.latLng is actually a Point then you can directly access the coordinates using the x and y properties (not methods).
What type of listener is creating the event?
Edit: there's an example in the tutorial of how to do what you want. It looks like you're following this already. Did you remember to include the actual placeMarker() function declaration?
function placeMarker(location) {
var clickedLocation = new google.maps.LatLng(location);
var marker = new google.maps.Marker({
position: location,
map: map
});
map.setCenter(location);
}
Or are you not interested in placing a marker, and just want to get the lat and lng values? In that case, all you need is:
google.maps.event.addListener(map, 'click', function(event) {
var myLatLng = event.latLng;
var lat = myLatLng.lat();
var lng = myLatLng.lng();
})
I am building an accommodation website where users can advertise their room with their address.
I want to know if i can use the zipcode to show the exact location in Gmaps which i believe would be much cooler.
I would be very thankful if someone can guide me with simple set of steps to do the same.
thanks in advance!
You may want to use the Client-side Geocoder in the Google Maps API, as in the following example:
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
var geocoder = new GClientGeocoder();
geocoder.setBaseCountryCode("us");
geocoder.getLatLng(
"90210",
function(point) {
if (point) {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
}
}
);
}
}
// ...
<div id="map_canvas" style="width: 500px; height: 300px"></div>
Simply change the "90210" parameter with the zip code of your users.
Check out the Google Maps API. You can use their geocoding service to convert a full address into coordinates, and then display a marker in a Google Map.
There are libraries available for various languages and platforms.
For PHP, here's an article on Geocoding in PHP (it refers to V2 of the Maps API, though; V3 is the brand-newest.)